home *** CD-ROM | disk | FTP | other *** search
/ Shareware Super Platinum 8 / Shareware Super Platinum 8.iso / mac / PROGTOOL / FGL304B.ZIP;1 / MANUALS.ARJ / USER15.DOC < prev    next >
Encoding:
Text File  |  1994-01-24  |  26.5 KB  |  647 lines

  1. Chapter 15
  2.  
  3.  
  4.  
  5.  
  6.  
  7. Sound Effects
  8.  
  9. 286   Fastgraph User's Guide
  10.  
  11.  
  12.  
  13. Overview
  14.  
  15.      In the realm of the IBM PC and PS/2 family of systems, a sound is
  16. defined by its frequency, duration, and volume.  The frequency of a sound is
  17. measured in units called Hertz.  While the PC and PS/2 can produce sounds
  18. ranging from 18 to more than one million Hertz, the average human can hear
  19. sounds between 20 and about 20,000 Hertz.  The length of a sound, called its
  20. duration, is expressed in clock ticks; there are either 18.2 of 72.8 clock
  21. ticks per second, depending on the method used to produce the sound.
  22. Finally, the volume determines the loudness of the sound.  As we'll see in
  23. this chapter, we can control a sound's volume only on the PCjr and Tandy 1000
  24. systems.
  25.  
  26.      Fastgraph contains several different methods for producing sound
  27. effects.  These include single tones, a series of tones expressed
  28. numerically, or a series of tones expressed as musical notes.  The sound
  29. effects may be discrete, continuous, or performed at the same time as other
  30. activity.  The sound-related routines are independent of the other parts of
  31. Fastgraph and do not require any initialization routines be called.
  32.  
  33.  
  34. Sound Sources
  35.  
  36.      All members of the PC and PS/2 families can produce sounds using the
  37. 8253-5 programmable timer chip and the internal speaker.  This method is
  38. limited to producing single sounds of given frequencies and durations,
  39. although we can combine these sounds to create interesting audio effects or
  40. play music.  When we use this technique, we have no control over the sound
  41. volume.  In fact, sound volumes often vary slightly on different systems
  42. because the physical properties of the speaker and its housing are not always
  43. the same.
  44.  
  45.      The PCjr and Tandy 1000 systems have an additional, more powerful chip
  46. for producing sounds.  This is the Texas Instruments SN76496A sound chip,
  47. called the TI sound chip for short.  The TI sound chip has three independent
  48. voice channels for producing pure tones, and a fourth channel for generating
  49. periodic or white noise.  Each voice channel has a separate volume control
  50. that allows us to control the loudness of the sound it emits.
  51.  
  52.  
  53. Synchronous Sound
  54.  
  55.      A sound effect is said to be synchronous if it is produced while no
  56. other activity is being performed.  In other words, a program makes a
  57. synchronous sound by starting the sound, waiting for a specified duration,
  58. and then stopping the sound.  The program must wait for the sound to complete
  59. before doing anything else.  As long as the duration is relatively short, the
  60. fact that the sound is synchronous has little or no effect on the program's
  61. execution speed.  Fastgraph includes routines for producing synchronous sound
  62. using either the 8253-5 programmable timer or the TI sound chip.
  63.  
  64.      The fg_sound routine uses the programmable timer to produce a sound of a
  65. given frequency and duration.  The frequency, defined by the first argument,
  66. is expressed in Hertz and must be an integer value between 18 and 32,767.
  67. The second argument defines the duration and is expressed in clock ticks;
  68.                                               Chapter 15:  Sound Effects   287
  69.  
  70.  
  71. there are 18.2 clock ticks per second.  If the duration is zero or negative,
  72. the sound will continue until it is stopped with the fg_quiet routine.
  73.  
  74.      Example 15-1 uses the fg_sound routine to create different sound
  75. effects, pausing for one second between each.  It first produces three
  76. distinct sounds of 20, 100, and 1,000 Hertz.  Each of these sounds lasts for
  77. approximately 1/6 of a second (three clock ticks).  The program then makes a
  78. warbling noise by quickly alternating sounds of similar frequencies.
  79. Finally, the program creates a sliding tone of increasing frequencies between
  80. 100 and 500 Hertz.  Each tone in this sequence lasts for two clock ticks, so
  81. it takes about 4.5 seconds to play the entire sequence.  In all cases,
  82. example 15-1 displays an identifying message just before each sound.
  83.  
  84.                                 Example 15-1.
  85.  
  86.               #include <fastgraf.h>
  87.               #include <stdio.h>
  88.               void main(void);
  89.  
  90.               void main()
  91.               {
  92.                  int freq;
  93.  
  94.                  printf("20 Hz tone...\n");
  95.                  fg_sound(20,3);
  96.                  fg_waitfor(18);
  97.  
  98.                  printf("100 Hz tone...\n");
  99.                  fg_sound(100,3);
  100.                  fg_waitfor(18);
  101.  
  102.                  printf("1000 Hz tone...\n");
  103.                  fg_sound(1000,3);
  104.                  fg_waitfor(18);
  105.  
  106.                  printf("warble...\n");
  107.                  fg_sound(400,1);
  108.                  fg_sound(410,1);
  109.                  fg_sound(400,1);
  110.                  fg_sound(410,1);
  111.                  fg_waitfor(18);
  112.  
  113.                  printf("sliding tone from 100 to 500 Hz...\n");
  114.                  for (freq = 100; freq <= 500; freq+=10)
  115.                     fg_sound(freq,2);
  116.               }
  117.  
  118.  
  119.      The fg_voice routine is analogous to the fg_sound routine, but it uses
  120. the TI sound chip rather than the programmable timer to create sound.  For
  121. this reason, the fg_voice routine can only be used on the PCjr or Tandy 1000
  122. systems.  The TI sound chip allows us to control the volume of a sound, and
  123. it also offers four distinct voice channels.  Thus, fg_voice requires two
  124. additional arguments besides frequency and duration to define the voice
  125. channel and sound volume.
  126. 288   Fastgraph User's Guide
  127.  
  128.      The first argument to fg_voice defines the voice channel, as shown
  129. below.
  130.  
  131.                   value  meaning
  132.  
  133.                     1    voice channel #1
  134.                     2    voice channel #2
  135.                     3    voice channel #3
  136.                     4    voice channel #4, periodic noise
  137.                     5    voice channel #4, white noise
  138.  
  139. If we use voice channels 1, 2, or 3, the second argument defines the sound
  140. frequency in Hertz, between 18 and 32,767.  If we use voice channel 4,
  141. however, the second argument instead is a value that represents a specific
  142. frequency, as shown in this table.
  143.  
  144.                        value   frequency
  145.  
  146.                          0     512 Hertz
  147.                          1    1024 Hertz
  148.                          2    2048 Hertz
  149.  
  150. The third argument defines the sound volume.  It must be between 0 and 15,
  151. where 0 is silent and 15 is loudest.  The fourth argument defines the sound
  152. duration in clock ticks.  As with the fg_sound routine, there are 18.2 clock
  153. ticks per second, and if the duration is zero or negative, the sound will
  154. continue until stopped with the fg_quiet routine.
  155.  
  156.      Example 15-2 uses the fg_voice routine to create different sound effects
  157. using the TI sound chip.  As in example 15-1, there is a pause of one second
  158. between each.  The program first calls the fg_testmode routine to be sure it
  159. is running on a PCjr or Tandy 1000 system (video mode 9 is only available on
  160. these systems).  If so, the program uses voice channel #4 to produce a 2,048
  161. Hertz periodic noise, followed by white noise of the same frequency.  Both
  162. sounds are emitted at the maximum volume level (15) and last for about 1/6 of
  163. a second each (three clock ticks).  After these noises, example 15-2 produces
  164. a 500 Hertz tone of increasing volume.  In all cases, the program displays an
  165. identifying message just before each sound.
  166.  
  167.                                 Example 15-2.
  168.  
  169.              #include <fastgraf.h>
  170.              #include <stdio.h>
  171.              #include <stdlib.h>
  172.              void main(void);
  173.  
  174.              void main()
  175.              {
  176.                 int volume;
  177.  
  178.                 if (fg_testmode(9,0) == 0) {
  179.                    printf("This program requires a PCjr or ");
  180.                    printf("a Tandy 1000 system.\n");
  181.                    exit(1);
  182.                    }
  183.  
  184.                 printf("2048 Hz periodic noise...\n");
  185.                                               Chapter 15:  Sound Effects   289
  186.  
  187.  
  188.                 fg_voice(4,2,15,3);
  189.                 fg_waitfor(18);
  190.  
  191.                 printf("2048 Hz white noise...\n");
  192.                 fg_voice(5,2,15,3);
  193.                 fg_waitfor(18);
  194.  
  195.                 printf("500 Hz tone of increasing volume...\n");
  196.                 for (volume = 1; volume <= 15; volume++) {
  197.                    fg_voice(1,500,volume,0);
  198.                    fg_waitfor(4);
  199.                    }
  200.  
  201.                 fg_quiet();
  202.              }
  203.  
  204.  
  205.      Note how example 15-2 uses a duration of zero (continuous sound) and the
  206. fg_waitfor routine to specify the duration for each volume level the 500
  207. Hertz tone sequence.  This causes the transition between changes in volume to
  208. blend better with each other.  The fg_quiet routine, which stops continuous
  209. sound started with the fg_sound or fg_voice routines, ends the sound after
  210. the final volume level.
  211.  
  212.      The fg_sound and fg_voice routines each produce a single sound.  We've
  213. seen how to combine sounds to produce sound effects, but still the individual
  214. sounds are defined numerically -- that is, by a certain frequency and
  215. duration.  It is often easier to create sounds from musical notes, and for
  216. this reason Fastgraph includes a routine fg_music that produces such sounds.
  217. The fg_music routine uses the programmable timer to produce synchronous
  218. sound; it does not support the TI sound chip.
  219.  
  220.      The fg_music routine has a single argument called the music string,
  221. passed by reference as a byte array or character string.  The music string is
  222. simply a variable-length sequence of music commands, followed by a dollar-
  223. sign ($) terminator.  Music commands are summarized in the following table.
  224.  
  225. command   meaning
  226.  
  227. A thru G  Play the specified note in the current octave.
  228.  
  229. #         May be appended to a note character (A through G) to make that note
  230.           sharp.
  231.  
  232. .         May be appended to a note character (A through G) or a sharp (#) to
  233.           extend that note by half its normal length.  Multiple dots may be
  234.           used, and each will again extend the note by half as much as the
  235.           previous extension.
  236.  
  237. Ln        Set the length of subsequent notes and pauses.  The value of n is
  238.           an integer between 1 and 64, where 1 indicates a whole note, 2 a
  239.           half note, 4 a quarter note, and so forth.  If no L command is
  240.           present, L4 is assumed.
  241.  
  242. On        Set the octave for subsequent notes.  The value of n may be an
  243.           integer between 0 and 6 to set a specific octave.  It also can be a
  244. 290   Fastgraph User's Guide
  245.  
  246.  
  247.           plus (+) or minus (-) character to increment or decrement the
  248.           current octave number.  Octave 4 contains middle C, and if no O
  249.           command is present, O4 is assumed.
  250.  
  251. P         Pause (rest) for the duration specified by the most recent L
  252.           command.
  253.  
  254. Sn        Set the amount of silence between notes.  The value of n is an
  255.           integer between 0 and 2.  If n is 0, each note plays for the full
  256.           period set by the L command (music legato).  If n is 1, each note
  257.           plays for 7/8 the period set by the L command (music normal).  If n
  258.           is 2, each note plays for 3/4 the period set by the L command
  259.           (music staccato).  If no S command is present, S1 is assumed.
  260.  
  261. Tn        Set the tempo of the music (the number of quarter notes per
  262.           minute).  The value of n is an integer between 32 and 255.  If no T
  263.           command is present, T120 is assumed.
  264.  
  265. The fg_music routine ignores any other characters in the music string.  It
  266. also ignores command values outside the allowable range, such as T20 or O8.
  267.  
  268.      Example 15-3 illustrates some uses of the fg_music routine.  The program
  269. plays the first few bars of "Mary Had a Little Lamb", followed by the musical
  270. scale (including sharps) in two octaves, and finally the introduction to
  271. Beethoven's Fifth Symphony.  There is a pause of one second between each
  272. piece of music, and the program displays the titles before playing the music.
  273. Blank characters appear in the music strings to help make them more readable.
  274.  
  275.                                 Example 15-3.
  276.  
  277.     #include <fastgraf.h>
  278.     #include <stdio.h>
  279.     void main(void);
  280.  
  281.     void main()
  282.     {
  283.        printf("Mary Had a Little Lamb...\n");
  284.        fg_music("T150 L8 EDCDEEE P DDD P EGG P EDCDEEE L16 P L8 EDDEDC$");
  285.        fg_waitfor(18);
  286.  
  287.        printf("up the scale in two octaves...\n");
  288.        fg_music("L16 CC#DD#EFF#GG#AA#B O+ CC#DD#EFF#GG#AA#B$");
  289.        fg_waitfor(18);
  290.  
  291.        printf("Beethoven's Fifth Symphony...\n");
  292.        fg_music("T180 O2 L2 P L8 P GGG L2 D# L24 P L8 P FFF L2 D$");
  293.     }
  294.  
  295.  
  296. Asynchronous Sound
  297.  
  298.      Sounds made concurrently with other activity in a program are said to be
  299. asynchronous.  Fastgraph's routines that produce asynchronous sound just
  300. start the sound and then immediately return control to the calling program.
  301. The sounds will automatically stop when the end of the sequence is reached,
  302. and you also can suspend or stop it on demand before that time.  None of
  303.                                               Chapter 15:  Sound Effects   291
  304.  
  305.  
  306. Fastgraph's asynchronous sound routines have any effect if there is already
  307. asynchronous sound in progress.  In addition, the asynchronous sound routines
  308. temporarily disable the synchronous sound routines (fg_sound, fg_voice, and
  309. fg_music) while asynchronous sound is in progress.
  310.  
  311.      To expand the range of sound effects and to play fast-tempo music,
  312. Fastgraph temporarily quadruples the clock tick interrupt rate from 18.2 to
  313. 72.8 ticks per second while producing asynchronous sound.  Because many disk
  314. controllers rely on the 18.2 tick per second clock rate to synchronize disk
  315. accesses, your programs should not perform any disk operations when
  316. asynchronous sound is in progress.
  317.  
  318.      The fg_sounds routine is the asynchronous version of the fg_sound
  319. routine.  It uses the programmable timer to play a sequence of tones
  320. simultaneous to other operations.  This routine expects as its first argument
  321. a variable-length integer array, passed by reference, containing pairs of
  322. frequency and duration values.  As with the fg_sound routine, each frequency
  323. is expressed in Hertz and must be between 18 and 32,767.  The durations are
  324. also measured in clock ticks, but because the interrupt rate is quadrupled,
  325. there are 72.8 instead of 18.2 ticks per second.
  326.  
  327.      The format of the frequency and duration array passed to fg_sounds is
  328. shown below.
  329.  
  330.                           [0]    frequency of sound 1
  331.  
  332.                           [1]    duration  of sound 1
  333.  
  334.                           [2]    frequency of sound 2
  335.  
  336.                           [3]    duration  of sound 2
  337.                                           .
  338.                                           .
  339.                                           .
  340.                                           .
  341.                                           .
  342.                        [2n-2]    frequency of sound n
  343.  
  344.                        [2n-1]    duration  of sound n
  345.  
  346.                          [2n]       terminator (0)
  347.  
  348. Note that a null character (that is, a zero byte) terminates the array.  The
  349. second argument passed to fg_sounds is an integer value indicating the number
  350. of times to cycle through the frequency and duration array.  If this value is
  351. negative, the sounds will continue until stopped with the fg_hush or
  352. fg_hushnext routines.
  353.  
  354.      Example 15-4 uses the fg_sounds routine to play the 100 to 500 Hertz
  355. sliding tone sequence of example 15-1.  To prove the sounds are being made
  356. concurrently with other operations, messages are displayed while the sequence
  357. is playing.  This is controlled by the Fastgraph routine fg_playing, which
  358. returns a value of 1 if asynchronous sounds are in progress, and 0 if not.
  359. Note how the duration must be specified as 8 clock ticks (instead of 2 as in
  360. example 15-1) to compensate for the quadrupled clock tick interrupt rate.
  361. 292   Fastgraph User's Guide
  362.  
  363.  
  364.                                 Example 15-4.
  365.  
  366.                  #include <fastgraf.h>
  367.                  #include <stdio.h>
  368.                  void main(void);
  369.  
  370.                  void main()
  371.                  {
  372.                     int i;
  373.                     int freq;
  374.                     int sound_array[83];
  375.  
  376.                     i = 0;
  377.  
  378.                     for (freq = 100; freq <= 500; freq+=10) {
  379.                        sound_array[i++] = freq;
  380.                        sound_array[i++] = 8;
  381.                        }
  382.                     sound_array[i] = 0;
  383.  
  384.                     fg_sounds(sound_array,1);
  385.  
  386.                     while(fg_playing())
  387.                        printf("Still playing...\n");
  388.                  }
  389.  
  390.  
  391.      Just as the fg_sounds routine is analogous to the fg_sound routine,
  392. there is a Fastgraph routine fg_voices that is similar to the fg_voice
  393. routine.  That is, fg_voices uses the TI sound chip to play an asynchronous
  394. sequence of tones.  Its arguments are the same as those of the fg_sounds
  395. routine, but the structure of the sound array is different.  Its structure
  396. is:
  397.  
  398.                           [0]    channel # of sound 1
  399.  
  400.                           [1]    frequency of sound 1
  401.  
  402.                           [2]    volume    of sound 1
  403.  
  404.                           [3]    duration  of sound 1
  405.                                           .
  406.                                           .
  407.                                           .
  408.                                           .
  409.                                           .
  410.                        [4n-4]    channel # of sound n
  411.  
  412.                        [4n-3]    frequency of sound n
  413.  
  414.                        [4n-2]    volume    of sound n
  415.  
  416.                        [4n-1]    duration  of sound n
  417.  
  418.                          [4n]       terminator (0)
  419.  
  420.                                               Chapter 15:  Sound Effects   293
  421.  
  422.  
  423. The channel numbers, frequencies, volumes, and durations must be in the same
  424. ranges as discussed in the description of the fg_voice routine, except the
  425. durations are quadrupled because of the accelerated clock tick interrupt
  426. rate.  Again, note that a null character (that is, a zero byte) terminates
  427. the array.
  428.  
  429.      Example 15-5 uses the fg_voices routine to play the 500 Hertz tone
  430. sequence of increasing volume introduced in example 15-2.  As in example
  431. 15-4, the program displays messages while the tone sequence is playing to
  432. demonstrate the sounds are being made concurrently with other operations.
  433. Note how the duration is now 16 clock ticks (instead of 4 as in example 15-2)
  434. because of the quadrupled clock tick interrupt rate.
  435.  
  436.                                 Example 15-5.
  437.  
  438.            #include <fastgraf.h>
  439.            #include <stdio.h>
  440.            void main(void);
  441.  
  442.            void main()
  443.            {
  444.               int voice_array[61];
  445.               int i;
  446.               int volume;
  447.  
  448.               if (fg_testmode(9,0) == 0) {
  449.                  printf("This program requires a PCjr or ");
  450.                  printf("a Tandy 1000 system.\n");
  451.                  exit(1);
  452.                  }
  453.  
  454.               i = 0;
  455.  
  456.               for (volume = 1; volume <= 15; volume++) {
  457.                  voice_array[i++] = 1;      /* use channel 1 */
  458.                  voice_array[i++] = 500;    /* 500 Hz frequency */
  459.                  voice_array[i++] = volume; /* variable volume */
  460.                  voice_array[i++] = 16;     /* duration */
  461.                  }
  462.               voice_array[i] = 0;
  463.  
  464.               fg_voices(voice_array,1);
  465.  
  466.               while(fg_playing())
  467.                  printf("Still playing...\n");
  468.            }
  469.  
  470.  
  471.      There is also an asynchronous version of the fg_music routine.  It is
  472. called fg_musicb, and it uses the same format music string as the fg_music
  473. routine does.  However, the fg_musicb routine has a second argument that
  474. specifies the number of times to cycle through the music string.  If this
  475. value is negative, the music will play repetitively until you stop it with
  476. the fg_hush or fg_hushnext routine.
  477. 294   Fastgraph User's Guide
  478.  
  479.      Example 15-6 plays the same three pieces of music as example 15-3, but
  480. it does so concurrently with other operations.  As the music plays, the
  481. program continuously displays the title of each piece.  Note how we can take
  482. advantage of the repetition in the music string for the "up the scale"
  483. sequence by playing the sequence twice.
  484.  
  485.                                 Example 15-6.
  486.  
  487.   #include <fastgraf.h>
  488.   #include <stdio.h>
  489.   void main(void);
  490.  
  491.   void main()
  492.   {
  493.      fg_musicb("T150 L8 EDCDEEE P DDD P EGG P EDCDEEE L16 P L8 EDDEDC$",1);
  494.      while (fg_playing())
  495.         printf("Mary Had a Little Lamb...\n");
  496.      fg_waitfor(18);
  497.  
  498.      fg_musicb("L16 CC#DD#EFF#GG#AA#B O+$",2);
  499.      while (fg_playing())
  500.         printf("up the scale in two octaves...\n");
  501.      fg_waitfor(18);
  502.  
  503.      fg_musicb("T180 O2 L2 P L8 P GGG L2 D# L24 P L8 P FFF L2 D$",1);
  504.      while (fg_playing())
  505.         printf("Beethoven's Fifth Symphony...\n");
  506.   }
  507.  
  508.      The next example demonstrates the effects of the Fastgraph routines
  509. fg_hush and fg_hushnext, which stop sounds started with the fg_sounds,
  510. fg_voices, or fg_musicb routines.  The fg_hush routine immediately stops
  511. asynchronous sound, whereas the fg_hushnext routine does so when the current
  512. cycle finishes.  Neither routine has any arguments, and neither routine has
  513. any effect if no asynchronous sound is in progress.  Furthermore, note that
  514. fg_hushnext has no effect unless the asynchronous sound is continuous.
  515.  
  516.      Example 15-7 runs in any text or graphics video mode.  It displays
  517. rectangles in up to 16 colors while playing continuous asynchronous music.
  518. The program periodically checks for keystrokes with the fg_intkey routine,
  519. and it continues to play the music while there is no keyboard activity.  If
  520. you press the Escape key, the program uses fg_hush to stop the music
  521. immediately; this causes an exit from the while loop.  If you press any other
  522. key, the program uses fg_hushnext to stop the music as soon as the current
  523. repetition finishes.  Once it does, the program exits the while loop because
  524. fg_playing will return a value of zero.
  525.  
  526.                                 Example 15-7.
  527.  
  528.       #include <fastgraf.h>
  529.       void main(void);
  530.  
  531.       #define ESC 27
  532.  
  533.       void main()
  534.       {
  535.  
  536.                                               Chapter 15:  Sound Effects   295
  537.  
  538.          int color;
  539.          int old_mode;
  540.          unsigned char key, aux;
  541.  
  542.          old_mode = fg_getmode();
  543.          fg_setmode(fg_automode());
  544.          color = 0;
  545.  
  546.          fg_musicb("O4 L16 CC#DD#EFF#GG#AA#B O+ CC#DD#EFF#GG#AA#B$",-1);
  547.  
  548.          while (fg_playing())
  549.          {
  550.             color = (color + 1) & 15;
  551.             fg_setcolor(color);
  552.             fg_rect(0,fg_getmaxx(),0,fg_getmaxy());
  553.  
  554.             fg_waitfor(4);
  555.             fg_intkey(&key,&aux);
  556.             if (key == ESC)
  557.                fg_hush();
  558.             else if (key+aux != 0)
  559.                fg_hushnext();
  560.          }
  561.  
  562.          fg_setmode(old_mode);
  563.          fg_reset();
  564.       }
  565.  
  566.      Example 15-7 also demonstrates an important side-effect of the fg_musicb
  567. routine when playing continuous music.  Any length, octave, silence, or tempo
  568. values changed within the string are not reset to their original values at
  569. the beginning of each repetition.  If we did not include the O4 command at
  570. the beginning of the string, the later O+ command would cause the music to
  571. play in octaves 4 and 5 during the first repetition, 5 and 6 during the
  572. second repetition, and octave 6 for all subsequent repetitions (because you
  573. cannot increase the octave number above 6).
  574.  
  575.      The final two routines relating to asynchronous sound are fg_resume and
  576. fg_suspend.  The fg_suspend routine suspends music previously started by
  577. fg_musicb, while fg_resume restarts the music from the point where it was
  578. suspended.  Example 15-8 plays the first few bars of "Mary Had a Little
  579. Lamb".  If you press any key while the song is playing, it stops.  Then,
  580. after another keystroke, the music resumes and continues until finished.
  581.  
  582.                                 Example 15-8.
  583.  
  584.   #include <fastgraf.h>
  585.   #include <stdio.h>
  586.   void main(void);
  587.  
  588.   void main()
  589.   {
  590.      fg_musicb("T150 L8 EDCDEEE P DDD P EGG P EDCDEEE L16 P L8 EDDEDC$",1);
  591.      fg_waitkey();
  592.  
  593.      fg_suspend();
  594.  
  595. 296   Fastgraph User's Guide
  596.  
  597.  
  598.      printf("Music suspended.  Press any key to resume.\n");
  599.      fg_waitkey();
  600.  
  601.      fg_resume();
  602.      printf("Music resumed.\n");
  603.      while (fg_playing());
  604.      printf("Music finished.\n");
  605.   }
  606.  
  607.  
  608. The fg_suspend routine has no effect if there is no asynchronous music in
  609. progress.  Similarly, fg_resume has no effect if there is no suspended music.
  610. If you call fg_suspend and then need to cancel the music or exit to DOS
  611. instead of restarting the music, call fg_hush instead of fg_resume.
  612.  
  613.  
  614. Summary of Sound Routines
  615.  
  616.      This section summarizes the functional descriptions of the Fastgraph
  617. routines presented in this chapter.  More detailed information about these
  618. routines, including their arguments and return values, may be found in the
  619. Fastgraph Reference Manual.
  620.  
  621.      FG_HUSH immediately stops asynchronous sound started with the fg_sounds,
  622. fg_voices, or fg_musicb routines.
  623.  
  624.      FG_HUSHNEXT is similar to fg_hush, but it does not stop the asynchronous
  625. sound until the current repetition finishes.
  626.  
  627.      FG_MUSIC uses the programmable timer to play a sequence of musical
  628. tones.
  629.  
  630.      FG_MUSICB is the asynchronous version of the fg_music routine.  It uses
  631. the programmable timer to play a sequence of musical tones, concurrent with
  632. other activity.
  633.  
  634.      FG_PLAYING determines whether or not there is any asynchronous sound in
  635. progress.
  636.  
  637.      FG_QUIET stops continuous synchronous sound started with the fg_sound or
  638. fg_voice routines.
  639.  
  640.      FG_RESUME restarts asynchronous music previously suspended by
  641. fg_suspend.
  642.  
  643.      FG_SOUND produces a tone of a specified frequency and duration using the
  644. programmable timer.
  645.  
  646.      FG_SOUNDS is the asynchronous version of the fg_sound routine.  It can
  647. play a series of tones of specified frequencies and durations, concurrent
  648. with other activity.
  649.  
  650.      FG_SUSPEND suspends asynchronous music previously started by fg_musicb.
  651.  
  652.      FG_VOICE produces a tone of a specified frequency, duration, and volume
  653. using one of the TI sound chip's four voice channels.
  654.                                               Chapter 15:  Sound Effects   297
  655.  
  656.  
  657.      FG_VOICES is the asynchronous version of the fg_voice routine.  It can
  658. play a series of tones of specified frequencies, durations, and volumes,
  659. concurrent with other activity.
  660. 298   Fastgraph User's Guide
  661.